package org.tamal.jsf;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;

/**
 * This class contains all the custom tag library functions.
 * @author Tamal Kanti Nath
 */
public final class TagLibraryFunctions {

    private TagLibraryFunctions() {
        // empty
    }

    /**
     * Return address part from full email.
     * @param email the email address
     * @return the email address
     * @throws AddressException if address cannot be parsed
     */
    public static String getEmailAddress(String email) throws AddressException {
        InternetAddress[] address = InternetAddress.parse(email, true);
        return address[0].getAddress();
    }

    /**
     * Return name/personal part from full email.
     * @param email the email address
     * @return the email personal
     * @throws AddressException if address cannot be parsed
     */
    public static String getEmailPersonal(String email) throws AddressException {
        InternetAddress[] address = InternetAddress.parse(email, true);
        return address[0].getPersonal();
    }
}
